/*
 * Socket.h
 *
 *  Created on: 06.11.2011
 *      Author: Pavel Sinay
 */

#ifndef SOCKET_H_
#define SOCKET_H_

#include <vector>

namespace net {

class Socket {
public:
	Socket();
	Socket(int fdsocket);
	virtual ~Socket();
	bool isConnected() const;
	void disconnect();
	void sendMessage(std::vector<char> const &msg);
	void receiveMessage(std::vector<char> &msg);

protected:
	int m_fdsocket;

	void waitWriteEnd();
	void waitReadReady();
	int sendBlock(const char *block, int length);
	int receiveBlock(char *block, int max_length);
	//bool isConnected();
	void throwException(const std::string &msg);

	void ensureWrite();
	void ensureRead();
};

}

#endif /* SOCKET_H_ */
